import qreust from '@/utils/requst'
//提交登录
/**
 *
 * @param {objcd} data 手机号 验证码
 * @returns Promise
 */
export const loginApi = (val1, val2) =>
  qreust({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile: val1,
      code: val2
    }
  })
//发送验证码
/**
 *
 * @param {string} mobile 手机号
 * @returns  返回Pormise
 */
export const getCoudeApi = (mobile) =>
  qreust({
    url: `/v1_0/sms/codes/${mobile}`
  })
//获取用户信息
export const useInfoApi = () =>
  qreust({
    url: '/v1_0/user'
  })
/**
 * 获取用户信息
 * @returns   Promise
 */
export const getUseaInfoApi = () =>
  qreust({
    url: '/v1_0/user/profile'
  })
/**
 * 修改个人资料
 * @param {Object} 传递一个对象
 * @returns  Promise
 */
export const changeInfo = (data) =>
  qreust({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data
  })
/**
 * 修改头像
 * @param {*}
 */
export const puhtochange = (file) => {
  // const fm = new FormData()
  // fm.append('photo', file)
  // qreust({
  //   url: '/v1_0/user/photo',
  //   method: 'PATCH',
  //   data: fm
  // })
  const fm = new FormData()
  fm.append('photo', file)
  return qreust({
    url: '/v1_0/user/photo',
    method: 'PATCH',
    data: fm
  })
}
/**
 * 对评论或者文章进行评论
 * @param {*} 对文章或者对评论的id
 * @param {*} 评论的内容
 * @param {*} 对评论进行评论需带上文章的id,如果只对文章进行评论则不需要
 * @returns Promise
 */
export const pinCommentsApi = (a, b, c) => {
  return qreust({
    url: '/v1_0/comments',
    method: 'POST',
    data: {
      target: a || '',
      content: b || '',
      art_id: c || ''
    }
  })
}
/**
 * 获取文章的评论
 * @param {number} 对文章或者评论的回复a 对文章,c 对评论
 * @param {number} 文章的id或者评论的id
 * @returns  Promise
 */
export const GetCommentsAppi = (a, b) => {
  return qreust({
    url: '/v1_0/comments',
    params: {
      type: a,
      source: b
    }
  })
}
/**
 * 收藏文章
 * @param {*} data
 * @returns
 */
export const collectionApi = (target) => {
  return qreust({
    url: '/v1_0/article/collections',
    method: 'POST',
    data: {
      target
    }
  })
}
export const oidcollectionaApi = (target) => {
  qreust({
    url: `/v1_0/article/collections/${target}`,
    method: 'DELETE'
  })
}
